package com.graduate.cec.controller;

import com.graduate.cec.common.JsonPage;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.pojo.dto.FeedbackSimpleDTO;
import com.graduate.cec.pojo.entity.Feedback;
import com.graduate.cec.pojo.vo.FeedbackVO;
import com.graduate.cec.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/feedback",produces = "application/json;charset=utf-8")
@Api(tags = "评论管理")
public class FeedbackController {
    @Resource
    private FeedbackService feedbackService;
    /****************        增       ******************************************************************/
    @GetMapping("/insert-feedback")
    @ApiOperation("增加评论")
    public JsonResult<Void> insertFeedback(Feedback feedback){
        feedbackService.insertFeedback(feedback);
        log.info("feedback:{}",feedback);
        return JsonResult.ok("插入成功");
    }



    /****************        删       ******************************************************************/
    @GetMapping("/delete-by-key")
    @ApiOperation("通过主键删除评论")
    public JsonResult<Void> deleteByKey(Long ids){
        log.info("ids:{}", ids);
        feedbackService.deleteByKey(ids);
        return JsonResult.ok("删除成功");
    }

    @GetMapping("/delete-by-keys/{ids}")
    @ApiOperation("通过主键删除评论")
    public JsonResult<Void> deleteByKeys(@PathVariable("ids") List<Long> ids){
        log.info("ids:{}", ids);
        feedbackService.deleteByKeys(ids);
        return JsonResult.ok("删除成功");
    }


    /****************        改       ******************************************************************/
    @PostMapping("/update-by-key")
    @ApiOperation("通过主键修改评论内容")
    public JsonResult<Void> updateByKey(@RequestBody Feedback feedback){
        log.info("feedback:{}",feedback);
        feedbackService.updateByKey(feedback);
        return JsonResult.ok("修改成功");
    }


    /****************        查        ******************************************************************/





    @GetMapping("/get-list-by-example")
    @ApiOperation("通过一定条件查找列表")
    public JsonResult<JsonPage<FeedbackVO>>getListByExample(FeedbackSimpleDTO feedbackSimpleDTO){
        return JsonResult.ok("查询成功",feedbackService.getListByExample(feedbackSimpleDTO));
    }


}
